//获取应用实例 
var app = getApp()
Page({
  data: {
    teamList: [
      ],
    swipertab: [{ name: '第一人市场', index: 0 }, { name: '第二人市场', index: 1 }],
    currentTab: 0,
    teamSize:0,
    nickname:'--',
    weixin:'--',
    teamDefaultImg:'/',
    referrer_num:0,
  },
  onShow:function(){
    
  },
  onReady:function(){
    this.getDeviceInfo();
  },
  onLoad: function () {
    this.getTeamList();
    this.setData({
      nickname:app.globalData.nickname,
      weixin:app.globalData.weixinid,
      avatar:app.globalData.avatar
    })
  },

  getDeviceInfo: function () {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          deviceW: res.windowWidth,
          deviceH: res.windowHeight
        })
      }
    })
  },

  copyWx:function(e){
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },


  //获取用户团队信息
  getTeamList() {
    var that = this;
    wx.request({
      url: app.globalData.api + '/app.php?c=User&a=getTeamList',
      data:
      {
        token: app.globalData.token,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            referrer_num: res.data.data.referrer_num,
            referrer_name: res.data.data.referrer_name,
            teamList2: res.data.data.teamlist2
          })
        } else {
          wx.showToast({
            title: '' + res.data.msg,
            icon: 'none',
            duration: 1000
          })
        }
        that.getTeamList2(that.data.currentTab);
      }, fail: function () {

      }
    });
  },

  //获取团队列表
  getTeamList2(currtTab) {
    var that = this;
    // if (currtTab==0){
    //   currtTab=1
    // }
    console.log(currtTab)
    wx.request({
      url: app.globalData.api + '/app.php?c=User&a=getTeamList2',
      data:
      {
        token: app.globalData.token,
        type: currtTab+1  
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            teamList: res.data.data.teamlist,
            teamSize: res.data.data.teamlist.length
          })
        } else {
          wx.showToast({
            title: '' + res.data.msg,
            icon: 'none',
            duration: 1000
          })
        }
      }, fail: function () {

      }
    });
  },
  // 截获竖向滑动
  catchTouchMove: function (res) {
    return false
  },
  onReady: function () {
    wx.setNavigationBarTitle({
      title: '我的市场'
    })
  },

  /**
 * 点击tab切换
 */
  swichNav: function (e) {

    var that = this;
    console.log(e)
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /**
     * 滑动切换tab
     */
  tabChange:function (e) {
    var that = this;
    console.log(e);
    that.setData({ currentTab: e.detail.current });
    that.getTeamList();
  },
  shareds:function(){
    wx.navigateTo({
      url: '/pages/mine/shared',
    })
  }
})
